package com.gsi.webstore.platform.storefront.internal.shipping;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.gsi.webstore.platform.storefront.capi.order.GSILineItemCtnrBO;
import com.gsi.webstore.platform.storefront.capi.order.GSIProductLineItemBO;
import com.gsi.webstore.platform.storefront.capi.shipping.GSIShippingMethodSelectionBucketBO;
import com.gsi.webstore.platform.storefront.internal.order.GSIProductLineItemBOImpl;
import com.intershop.sellside.appbase.b2c.capi.calculation.LineItemCtnrCalculationResultView;
import com.intershop.sellside.appbase.b2c.capi.order.LineItemCtnrContext;
import com.intershop.sellside.appbase.b2c.capi.order.ProductLineItemBO;
import com.intershop.sellside.appbase.b2c.capi.shipping.ShippingMethodSelectionBucketBO;

public class GSIShippingMethodSelectionBucketBOImpl implements GSIShippingMethodSelectionBucketBO
{
    private ShippingMethodSelectionBucketBO _delegate;
    private GSILineItemCtnrBO _parent;
    private LineItemCtnrCalculationResultView _calculationResultView;

    public GSIShippingMethodSelectionBucketBOImpl(ShippingMethodSelectionBucketBO bucket, GSILineItemCtnrBO parent,
                    LineItemCtnrContext context, final LineItemCtnrCalculationResultView calculationResultView)
    {
        _delegate = bucket;
        _parent = parent;
        _calculationResultView = calculationResultView;
    }

    @Override
    public Collection<? extends GSIProductLineItemBO> getProductLineItemBOs()
    {
        Collection<? extends ProductLineItemBO> pliBOs = _delegate.getProductLineItemBOs();

        if (pliBOs != null)
        {
            List<GSIProductLineItemBO> gsiPliBOs = new ArrayList<GSIProductLineItemBO>();

            for(ProductLineItemBO pliBO : pliBOs)
            {
                gsiPliBOs.add(createProductLineItemBO(pliBO));
            }

            return gsiPliBOs;
        }

        return null;
    }

    private GSIProductLineItemBO createProductLineItemBO(ProductLineItemBO pliBO)
    {
        return new GSIProductLineItemBOImpl(pliBO, _parent, _calculationResultView);
    }

}
